home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / TEXTEDIT.SWG / 0003_FORMAT1.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  85 lines

  1. {
  2. > - How can I get TP to make what ever the user enters in to CAPS or     │
  3. >   NONCAPS?  Example:                                                   │
  4. >                     Enter Name -> ChRiS BrAtEnE                        │
  5. >                     Your name is Chris Bratene? (Y/n)?                 │
  6.  
  7.  
  8. I just wrote a routine that does this on the fly, so to speak, For
  9. another user, and I haven't erased it yet, so here it is (slightly
  10. modified, so that it Forces lowerCase, too):
  11. }
  12.  
  13. Uses
  14.   Crt;
  15.  
  16. Procedure Backspace;
  17. begin
  18.   Write(#8' '#8)
  19. end;
  20.  
  21. Function LoCase(ch : Char) : Char;
  22. begin
  23.   if ch in ['A'..'Z'] then
  24.     LoCase := Char(ord(ch)+32)
  25.   else
  26.     LoCase := ch;
  27. end;
  28.  
  29. Procedure Dibble(Var st : String);
  30. { Forces upperCase For first letter in each Word,
  31.   lowerCase For other letters. }
  32. Var
  33.   len : Byte Absolute st;
  34.   ch : Char;
  35.  
  36.   Function ForceCap : Boolean;
  37.   begin
  38.     ForceCap := (len = 0) or (st[len] = ' ');
  39.   end;
  40.  
  41. begin
  42.   st := '';
  43.   Repeat
  44.     ch := ReadKey;
  45.     if ForceCap then
  46.       ch := upCase(ch)
  47.     else
  48.       ch := LoCase(ch);
  49.     Case ch of
  50.       #8  : if len > 0 then
  51.             begin
  52.               Backspace;
  53.               dec(len);
  54.             end;
  55.       #27 : While len > 0 do
  56.             begin
  57.               BackSpace;
  58.               dec(len);
  59.             end;
  60.       #0  : ch := ReadKey;
  61.  
  62.       else
  63.         begin
  64.           Write(ch);
  65.           st := st + ch;
  66.         end;
  67.  
  68.     end;
  69.   Until ch in [#13,#27];
  70.  
  71.   Writeln;
  72.  
  73. end;
  74.  
  75.  
  76. Var
  77.   st : String;
  78.  
  79. begin { test }
  80.   Writeln;
  81.   Write('Enter String:  ');
  82.   Dibble(st);
  83.   Writeln(st);
  84. end.
  85.